package tt.dz.biz.service.oper;

import java.util.HashSet;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import tt.dz.biz.dao.common.CommonDAO;
import tt.dz.biz.dao.oper.OperDAOImpl;
import tt.dz.biz.service.BaseService;
import tt.dz.common.LogUtil;
import tt.dz.vo.Authority;
import tt.dz.vo.OperListVO;
import tt.dz.vo.Operator;

@Service("operService")
public class OperService
  extends BaseService
{
  @Resource(name="operDAO")
  OperDAOImpl operDAOImpl;
  @Resource(name="commonDAO")
  CommonDAO cmmDao;
  
  public Operator queryOperatorByMobile(Operator oper)
  {
    try
    {
      Operator rsOper = this.operDAOImpl.queryOpterByMobile(oper);
      List<Authority> autorList = this.operDAOImpl.queryAuthorityByMobileAndSubsysId(rsOper);
      rsOper.setAuthoritySet(new HashSet(autorList));
      return rsOper;
    }
    catch (Exception e)
    {
      LogUtil.error("查询用户信息和权限异常", e);
    }
    return new Operator();
  }
  
  public Operator queryOperatorByID(String operId)
  {
    return this.operDAOImpl.queryOpterByID(operId);
  }
  
  public int updateOper(OperListVO oper)
    throws Exception
  {
    try
    {
      oper.setUpdatedTime(this.cmmDao.getDBCurrentTime());
      return this.operDAOImpl.updateOperList(oper);
    }
    catch (Exception e)
    {
      LogUtil.error("更新操作人员信息异常，参数为：oper=" + oper, e);
      throw e;
    }
  }
}
